package ReefStats::Schema::ReefStatsDB;

use strict;
use warnings;
use YAML qw/LoadFile/;
use Hash::Merge qw/merge/;
use FindBin;
use base 'DBIx::Class::Schema';

__PACKAGE__->load_classes(
    qw(
      ActionsAll
      ActionsDomain
      Actions
      ActionsReasons
      ActionsReasonsHourly
      ActionsReasonsAll
      ActionsReasonsAllHourly
      ActionsReasonsDomain
      ActionsReasonsDomainHourly
      ActionsReasonsUser
      ActionsReasonsUserHourly
      ActionsUser
      BlacklistedReasonexts
      BlacklistedReasonextsHourly
      Clusters
      Domains
      Maillog
      ReasonsAll
      ReasonsDomain
      Reasons
      ReasonsUser
      Roles
      UserRoles
      Users
      )
);

sub connect_for_testing {
    my $global_config_file = "$FindBin::Bin/../reefstats.yml";
    my $local_config_file  = "$FindBin::Bin/../reefstats_local.yml";
    my $config             = LoadFile($global_config_file);

    if ( -e $local_config_file ) {
        my $local_config = LoadFile($local_config_file);
        $config = merge $local_config, $config;
    }

    return ReefStats::Schema::ReefStatsDB->connect(
        @{ $config->{'Model::ReefStatsDB'}->{connect_info} } );
}

sub connect_via_config {
    return connect_for_testing();
}

1;

__END__

=pod

=head1 NAME

ReefStats::Schema::ReefStatsDB

=head1 DESCRIPTION

Base of the ReefStats schema

=cut
